/*
 * jiyan
 */
package com.jiyan.persons.ctrl;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.data.redis.core.RedisTemplate;
import springfox.documentation.annotations.ApiIgnore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Resource;
import com.rzhkj.core.tools.redis.RedisUtils;
import com.rzhkj.core.tools.StringTools;
import com.rzhkj.core.entity.BeanRet;
import com.rzhkj.core.entity.Page;
import com.jiyan.core.base.BaseCtrl;
import com.jiyan.persons.facade.PersonsSV;
import com.jiyan.persons.entity.Persons;



/**
 * 
 *
 * @author jiyan
 */
@Controller
@RequestMapping("/persons")
@Api(value = "控制器", description = "控制器")
public class PersonsCtrl extends BaseCtrl {
 private final static Logger logger = LoggerFactory.getLogger(PersonsCtrl.class);

    @Resource
    protected RedisTemplate<String, Object> redisTemplate;
    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private PersonsSV personsSV;


    /**
     * 查询信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询信息集合", notes = "查询信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "idP", value = "", paramType = "query"),
            @ApiImplicitParam(name = "lastName", value = "", paramType = "query"),
            @ApiImplicitParam(name = "firstName", value = "", paramType = "query"),
            @ApiImplicitParam(name = "address", value = "", paramType = "query"),
            @ApiImplicitParam(name = "city", value = "", paramType = "query")
    })
    @GetMapping(value = "/list")
    @ResponseBody
    public BeanRet list(@ApiIgnore Persons persons,@ApiIgnore Page<Persons> page) {
        if (page == null) {
                return BeanRet.create(false, "分页对象不能为空");
        }
        page.setParams(JSON.parseObject(JSON.toJSONString(persons)));
        page = personsSV.getList(page);
        return BeanRet.create(true, "", page);
    }

    /**
     * 创建
     *
     * @return BeanRet
     */
    @ApiOperation(value = "创建", notes = "创建")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "idP", value = "", paramType = "query", required = true),
            @ApiImplicitParam(name = "lastName", value = "", paramType = "query", required = true),
            @ApiImplicitParam(name = "firstName", value = "", paramType = "query", required = true),
            @ApiImplicitParam(name = "address", value = "", paramType = "query", required = true),
            @ApiImplicitParam(name = "city", value = "", paramType = "query", required = true)
    })
    @PostMapping("/save")
    @ResponseBody
    public BeanRet save(@ApiIgnore Persons persons) {
        personsSV.save(persons);
        return BeanRet.create(true, "保存成功");
    }


    /**
     * 修改
     *
     * @return BeanRet
     */
    @ApiOperation(value = "修改", notes = "修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "idP", value = "", paramType = "query"),
            @ApiImplicitParam(name = "lastName", value = "", paramType = "query"),
            @ApiImplicitParam(name = "firstName", value = "", paramType = "query"),
            @ApiImplicitParam(name = "address", value = "", paramType = "query"),
            @ApiImplicitParam(name = "city", value = "", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public BeanRet modify(@ApiIgnore Persons persons) {
        personsSV.update(persons);
        return BeanRet.create(true, "修改成功");
    }

    /**
     * 删除
     *
     * @return BeanRet
     */
    @ApiOperation(value = "删除", notes = "删除")
    @ApiImplicitParams({
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete() {
        personsSV.delete();
        return BeanRet.create(true, "删除Persons成功");
    }

}
